import React from 'react';
import {Button, Input,InputNumber, message,Modal,Card,Radio} from 'antd';
import OfferedController from '@/services/OfferedProject/OfferedController';
import { UseSearch, UseTable } from '@/components';

const {TextArea}= Input
const {confirm} = Modal
class CompleteRecord extends React.Component {
    constructor(props) {
        super(props);
        this.state = { datas:{},rowData:props.rowData,userInfo:JSON.parse(sessionStorage.getItem('userInfo')) };
    }
    componentDidMount(){
        // this.props.onRef(this)
    }
    handleChange=(datas)=>{
        this.setState({datas})
    }
    getList=(query)=>{
        let {userInfo,rowData} = this.state
        let level = ''
        if(userInfo.roleName.indexOf("省级")!==-1){
            level='省级'
        }
        if(userInfo.roleName.indexOf("市级")!==-1){
            level='市级'
        }
        query.level = level
        query.projectCode = rowData.projectCode
        return OfferedController.getApplyRecordList(query)
    }
    reviewSubmit=(rowData,type)=>{
        
    }
    freshen=()=>{
        this.setState({freshen:!this.state.freshen})
    }
    handleSearch=(query)=>{
        this.setState({query})
        this.freshen()

    }
    reset=()=>{
        this.setState({query:{}})
        this.freshen()

    }
    inputChange=(key,e)=>{
        let {datas} = this.state
        datas[key] = e.target?e.target.value :e
        this.setState({datas})
    }
    submit=()=>{
        let {datas,rows,userInfo} = this.state
        if(!datas.result){
            message.error('请选择审核结果',3)
            return
        }
        if(!datas.result==="不合格"&&!datas.remark){
            message.error('请输入审核不合格的原因',3)
            return
        }
        let params = {
            ...datas,
            id:rows.id,
            userName:userInfo.userName,
            name:userInfo.name,
        }
        let that = this
        confirm({
            title:"提示",
            content:'确定要提交吗？',
            onOk(){
                OfferedController.resultReview(params).then(r=>{
                    if(r&&r.data===1){
                        message.success('操作成功')
                        that.freshen()
                        that.setState({
                            visibleResultReview:false
                        })
                    }
                })
            }
        })
    }
    showResultReview=(rows)=>{
        this.setState({
            rows,
            visibleResultReview:true
        })
    }
    toFiles=(text)=>{
        this.setState({
            visibleFile:true,
            dataSource:JSON.parse(text)
        })
    }
    render() {
        const {query,freshen,visibleResultReview,visibleFile} = this.state
        const columns=[
            {title:'项目名称',dataIndex:'projectName'},
            {title:'接收时间',dataIndex:'createdAt'},
            // {title:'作品提交时间',dataIndex:'submitAt'},
            {title:'作品文件数量',dataIndex:'fileItems',render:text=>text&&<a onClick={this.toFiles.bind(this,text)}>查看</a>},
            {title:'作品提交人',dataIndex:'name'},
            {title:'领取时间',dataIndex:'createdAt'},
            {title:'状态',dataIndex:'status'},
            {title:'得分',dataIndex:'score'},
            {title:'审核状态',dataIndex:'reviewResult'},
            {title:'审核备注',dataIndex:'reviewRemark'},
            {title:'操作',render:((text,row,index)=>(
                <div>
                    {row.reviewResult==='待审核'&&<Button type={'primary'} onClick={this.showResultReview.bind(this,row)}>成果审核</Button>}
                </div>
            ))},
        ]
        return (
            <div>
                {/* <Card>          
                    <UseSearch />
                </Card> */}
                <Card>
                    <UseTable columns={columns} getData={this.getList} bordered rowKey={'projectCode'} refresh={freshen} query={query}/>
                </Card>
                {visibleResultReview&&<Modal
                visible={visibleResultReview}
                title={'成果评审'}
                onCancel={()=>this.setState({visibleResultReview:false})}
                onOk={this.submit}
                width={500}
                >
                    <div>
                        <strong>评审结果：</strong>
                        <Radio.Group onChange={this.inputChange.bind(this,'result')} style={{width:350}}>
                            <Radio value={"合格"} key={1}>合格</Radio>
                            <Radio value={"不合格"} key={2}>不合格</Radio>
                        </Radio.Group>
                    </div>
                    <div>
                        <strong style={{verticalAlign:"top"}}>评审备注：</strong>
                        <Input.TextArea placeholder="请输入" onChange={this.inputChange.bind(this,'remark')} style={{width:350}}></Input.TextArea>
                    </div>
                </Modal>}
                {visibleFile&&<Modal
                visible={visibleFile}
                onCancel={()=>this.setState({visibleFile:false})}
                footer={false}
                >
                    <Table dataSource={dataSource} columns={fileColumns} bordered rowKey={'url'} />
                </Modal>}
            </div>
        );
    }
}

export default CompleteRecord;